package com.uikoo9.plugin;

import com.uikoo9.util.jfinal.QInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 * User: user
 * Date: 15-7-25
 * Time: 下午9:59
 * To change this template use File | Settings | File Templates.
 */
public class QLogger1 {
    /**
     * logger.trace("======trace");
     logger.debug("======debug");
     logger.info("======info");
     logger.warn("======warn");
     logger.error("======error");
     */

    /*StackTraceElement stack[] = Thread.currentThread().getStackTrace();

		System.out.println(stack[0]);//java.lang.Thread.getStackTrace
		System.out.println(stack[1]);//本方法的位置及所属类 com.test.A.test(B.java:10)
		System.out.println(stack[2]);//调用本方法的类       com.test.B.main(B.java:4)
		System.out.println("调用本方法是:"+stack[2].getClassName()+"类中的"+stack[2].getMethodName()+"方法");
		System.out.println("调用本方法的文件是"+stack[2].getFileName());
		String callName=stack[2].getClassName();
		System.out.println("调用test方法的类是："+callName);
		//然后就可以根据调用本方法的类做一些限制或其他操作
		if (callName.endsWith("B")){
			System.out.println("B类调用了A类的test方法");
		}else{

		}*/


    public static Logger getLogger(){
        StackTraceElement stack[] = Thread.currentThread().getStackTrace();
        System.out.println(stack[0]);//java.lang.Thread.getStackTrace

        Logger logger = null;
        try {
            logger = LoggerFactory.getLogger(Class.forName(stack[2].getClassName()));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        if (logger == null)
        {
            logger =  LoggerFactory.getLogger(QLogger1.class);
        }
        return logger;
    }

}
